package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseStudentDao {
//        private Student[] students = new Student[5];
        ArrayList<Student> students = new ArrayList<>();

        public boolean addStudent(Student student) {
            students.add(student);
            return true;
    }

    public Student[] findAllStudent() {
        Student[] students1 = new Student[this.students.size()];
        for (int i = 0; i < students1.length; i++) {
            students1[i] = students.get(i);
        }
        return students1;
    }

    public void deleteById(String id) {
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i) != null && students.get(i).getId().equals(id)){
                students.remove(i);
            }
        }
    }

    public void updateStudent(Student student) {
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i) != null && students.get(i).getId().equals(student.getId())){
                students.set(i,student);
            }
        }
    }
}
